import java.util.Calendar;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

public class BillTableModel extends AbstractTableModel {
	public static final int COL_DESCR = 0;
	public static final int COL_LASTPAID = 1;
	public static final int COL_NEXTPAY = 2;
	public static final int COL_PAYBILL = 3;

	protected Wallet w;
	protected Vector <Bill> billList;

	private String[] columnNames = {"Description", "Last Paid Date", "Next Pay Date", "Pay Bill"};

	public BillTableModel() {
		w = null;
		billList = null;
	}    	

	public int getRowCount() {
		return billList == null ? 0 : billList.size();
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public boolean isCellEditable(int nRow, int nCol) {
		return true;
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Bill getBillAt(int nRow){
		return(Bill)billList.elementAt(nRow);
	}

	public Object getValueAt(int nRow, int nCol) {
		if (nRow < 0 || nRow>=getRowCount())
			return "";
		Bill row = (Bill)billList.elementAt(nRow);

		switch (nCol) {
		case COL_DESCR: return row.getDescription();
		case COL_LASTPAID: return row.getLastPaidDate().getTime();
		case COL_NEXTPAY: return row.getNextPayDate().getTime();
		}
		return "";
	}

	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	/*
	 * Don't need to implement this method unless your table's
	 * data can change.
	 */
	public void setValueAt(Object value, int nRow, int nCol) {
		if (nRow < 0 || nRow>=getRowCount())
			return;
		Bill row = (Bill) billList.elementAt(nRow);
		String svalue = value.toString();

		switch (nCol) {
			case COL_DESCR: row.setDescription(svalue);
				break;
			case COL_LASTPAID: row.setLastPaidDate((Calendar)value);
				break;
			case COL_NEXTPAY: row.setNextPayDate((Calendar)value);
				break;
			case COL_PAYBILL: 
		}

	}

	public void setWallet(Wallet w){
		this.w = w;
		billList = w.getBillList();
	}
	
	public Vector<Bill> getBillList() {
		return billList;
	}
}